/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//图片上传

$(".fileupload").fileupload({
        url: homeUrl+'/public/upload',
        dataType: 'json',
        add: function (e, data) {
            var _type = $(this).data('num');
            if(_type>1){
                var numItems = $(this).parent().find('.images_zone').length;
                if (numItems >= _type) {
                    alert('提交照片不能超过'+_type+'张');
                    return false;
                }
            }
            $('.up_progress .progress-bar').css('width', '0px');
            jQuery(this).siblings('.up_progress').show();
            jQuery(this).siblings('.up_progress').find(' .progress-bar').html('Uploading...');
            data.submit();
        },
        done: function (e, data) {
            var _type = $(this).data('num');
            var name = $(this).data('name');
            $('.up_progress').hide();
            $('.upl').remove();
            var d = data.result;
            if (d.status == 0) {
                alert("上传失败");
            } else {
                var imgshow = '<div class="images_zone"><input type="hidden" name="'+name+'" value="' + d.msg + '" /><span><img src="' + d.msg + '!100x100"  /></span><a class="deldre_img" href="javascript:;">删除</a></div>';
                if(_type==1){
                    jQuery(this).siblings('.files').html(imgshow);
                }else{
                    jQuery(this).siblings('.files').append(imgshow);
                }
            }
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('.up_progress .progress-bar').css('width', progress + '%');
        }
    });

//图片删除
$('.files').on({
    mouseenter: function () {
        $(this).find('.deldre_img').show();
    },
    mouseleave: function () {
        $(this).find('.deldre_img').hide();
    },
}, '.images_zone');
$('.files').on('click', '.deldre_img', function () {
    $(this).parent().remove();
});






